# 1、写函数,将传入的列表或元祖对象的奇数位索引对应的元素,
# list_number =[]
# def list_(*a):
#     list_number = a
#     return list_number
# print(list(list_(1,2,3,4,5,6,7,8,9))[0::2])
# print(type(list_(1,2,3,4,5,6,7,8,9)[0::2]))
# 2、写函数,判断用户传入的对象(string,list,tuple)长度是否大于5
# def len_str(str_name):
#     if len(str_name)>5:
#         return "您输入的字符串长度大于5"
#     elif len(str_name)<5:
#         return "您输入的字符串长度小于5"
#     elif len(str_name)==5:
#         return "您输入的字符串长度等于5"
# str_name = input("请输入您要判断的字符串:")
# print(len_str(str_name))
# 3、写函数,计算传入的string中,数字,字母,空格以及其它内容的个数,并返回结果
# import string
# str_a_l = string.ascii_letters
# number_n = [str(i) for i in range(10)]
# print(number_n)
# def count_str(str_):
#     letter_number = 0
#     number_num = 0
#     space_num = 0
#     for i in str_:
#         for j in str_a_l:
#             if i == j:
#                 letter_number +=1
#             else:
#                 continue
#         for n in number_n:
#             if i == n:
#                 number_num +=1
#             else:
#                 continue
#         if i == " ":
#             space_num +=1
#         else:
#             continue
#     return letter_number,number_num,space_num
# str_s = input("请输入您要判断的字符串")
# letters_num,number_num,space_num = count_str(str_s)
# print(f"字母个数为：{letters_num},数字个数为：{number_num}，空格个数为：{space_num}")
# 4、写函数,接收两个数字参数,返回较大的那个数字
# def max_number(first_nu,second_nu):
#     if first_nu>second_nu:
#         return first_nu
#     else:
#         return second_nu
# number_n1 = input("请输入要判断的第一个数：")
# number_n2 = input("请输入要判断的第二个数：")
# print(f"较大的数字为：{max_number(number_n1,number_n2)}")
# 5、佩奇去超市购买54元巧克力和53元果冻，货币面值有20、10、2、1元，按付款货币数量最少原则，佩奇需要付给超市多少数量的货币，编写函数实现该算法。
# def count_m(price):
#     count_20 = 0
#     count_10 = 0
#     count_2 = 0
#     count_1 = 0
#     if price // 20 !=0:
#         count_20 = (price//20)
#         price = price - count_20*20
#     if price // 10 !=0:
#         count_10 =(price//10)
#         price = price -count_10*10
#     if price // 2 != 0:
#         count_2 =(price//2)
#         price = price -count_2*2
#     if price // 1 !=0:
#         count_1 = (price//1)
#         price = price -count_1
#     return count_20,count_10,count_2,count_1
# sum_price = int(input("请输入要判断的价格："))
# count_20,count_10,count_2,count_1 = count_m(sum_price)
# print(f"20元金额：{count_20}张，10元金额：{count_10}张，2元金额：{count_2}张，1元金额：{count_1}张")
# 6、编写一个函数cacluate, 可以接收任意多个数,返回的是一个元组.
# 元组的第一个值为所有参数的平均值, 第二个值是大于平均值的所有数.
# sum = 0
# avg_number = 0
# count_set = 0
# list = []
# def cacluate(*set_):
#     global sum,avg_number,count_set,list
#     set_2 = ()
#     for i in set_:
#         sum +=i
#         count_set +=1
#     avg_number = sum/count_set
#     def avg(avg_number):
#         for i in set_:
#             if avg_number < i:
#                 list.append(i)
#         return list
#     set_2 = tuple(avg(avg_number))
#     return avg_number,set_2
# list_ = []
# number_input = input("请输入您要判断的数：中间用空格隔开！").split()
# for  i  in number_input:
#     list_.append(int(i))
# print(cacluate(*list_))

# 7、编写一个函数, 接收字符串参数, 返回一个元组,
# 元组的第一个值为大写字母的个数, 第二个值为小写字母个数.
# import string
# def tuple_number_str(str_inp):
#     lowercase_letters = string.ascii_lowercase
#     lowercase_letters_number = 0
#     number_digit = [str(i) for i in range(10)]
#     number_num = 0
#     for i in str_inp:
#         if i in lowercase_letters:
#             lowercase_letters_number +=1
#         if i in number_digit:
#             number_num +=1
#     return lowercase_letters_number,number_num
# Str_in = input("请输入您要判断的字符串：")
# print(tuple_number_str(Str_in))
# 8、编写函数, 接收一个列表(包含30个1~100之间的随机整形数)
# 和一个整形数k, 返回一个新列表.
# 函数需求:
# 将列表下标k之前对应(不包含k)的元素逆序;
# 将下标k及之后的元素逆序;
# import random
# list_number = []
# for i in range(30):
#     number = random.randint(1,100)
#     list_number.append(number)
# def list_def(list_number,k):
#     print(list_number)
#     print(list_number[0:k-1])
#     print(list_number[:k-2:-1])
# list_k = int(input("请输入您要判断的下标："))
# list_def(list_number,list_k)
# 9、编写函数，从键盘输入参数x和n，计算并显示形如x+xx +xxx + xxxx + xxxxx+xxx…xxx+ 的表达式前n项的值
# def sum_x(x,n):
#     sum = 0
#     for i in range(1,n+1):
#         k = 0
#         for j in range(0,i):
#             k += x * pow(10,j)
#         sum +=k
#     print(sum)
# number_x = int(input("请输入X的值："))
# number_xu = int(input("请输入X的次数："))
# sum_x(number_x,number_xu)
# 10、写函数,函数接收的4个参数分别是:姓名,性别(默认为男),年龄,地址
#
# 用户通过input输入这4个内容(支持持续输入,Q或q退出),并传递给函数
#
# 函数接收到这些内容,将其追加到student_msg文件中
#
# 重点:复习文件操作
# import  os
# import json
# def dict_l(name,sex,age,address):
#     dict = {"姓名":name,"性别":sex,"年龄":age,"地址":address}
#     file_path = os.path.abspath('./student_msg.txt')
#     for i,j in dict.items():
#         # with open(file_path,"w",encoding='utf-8') as file:
#         #     file.write(str(i))
#         file = open(file_path,"a",encoding='utf-8')
#         Personal_Information = file.write(i+":")
#         Personal_Information = file.write(str(j)+"    ")
#     Personal_Information = file.write("\n")
#     file.close
#     print(dict)
# person_name = input("请输入姓名：")
# person_sec = input("请输入性别：如果不输入默认为男")
# person_age = input("请输入年龄:")
# person_address = input("请输入地址：")
# if person_sec == "男":
#     person_sec = "男"
# elif person_sec =="女":
#     person_sec ="女"
# else:
#     person_sec ="男"
# dict_l(person_name,person_sec,person_age,person_address)
# 11、写函数,接收n个数字,返回这些数字的和(动态传参)
# sum = 0
# def number_sum(*a):
#     for i in a:
#         global sum
#         sum +=i
#     return sum
# list_ = []
# number_tuple = input("请输入要计算的数字：中间用空格隔开!!").split()
# for  i in number_tuple:
#     list_.append(int(i))
# number_sum_n = number_sum(*list_)
# print(f"总和是：{number_sum_n}")
# 12、在实参中传入多个可迭代对象(要有string,list,tuple,set,dict),将每个对象的每个元素都加到args或kwargs里
# def func_object(*args,**kwargs):
#     print(args)
#     print(kwargs)
# func_object('1','ads','aga','gae',姓名="student_name",性别="student_sex",年龄="student_age",城市="student_address")
# 13、写函数,把传过来的列表中的每一个元素都用"_"拼接,并返回
# new_list = []
# def list_join(list):
#     j = 0
#     for i in list:
#         global new_list
#         new_list.append(i)
#         if j < len(list)-1:
#             new_list.append("_")
#             j+=1
#     print(*new_list)
#         # print(i,end="_")
# list = list(input("请输入您要判断的列表"))
# list_join(list)
# 14、写函数,传入一个数字,返回这个数的阶乘
# 重点:累乘
#
# 示例：1x2x3....
# def factorial(number):
#     result = 1
#     for i in range(1,number+1):
#         result *=i
#     return result
# number_sum = int(input("请输入您要算的阶乘："))
# print(f"总和为：{factorial(number_sum)}")
# 15、写函数,返回一个扑克牌列表,里面有52项,每一项都是一个tuple
# pocker_tuple = []
# def pocker():
#     decor = ("梅花","方片","桃花","黑桃")
#     check_number = ("A","2","3","4","5","6","7","8","9","10","J","Q","K")
#     for  i in decor:
#         for j in check_number:
#             pocker_tuple.append(i)
#             pocker_tuple.append(j)
#     return pocker_tuple
# print(pocker())
# 16、用代码写一个99乘法表
# def multiplication():
#     for i in range(1,10):
#         for  j in range(1,i+1):
#             print(f"{j}*{i}={i*j}",end=" ")
#         print()
# multiplication()
# 17、编写函数，求1+2+3+…N的和
# sum = 0
# def sum_number(number):
#     for i in range(number):
#         if number > 0 :
#             global sum
#             sum +=number
#             number = number -1
#     return sum
# number_in = int(input("请输入您要算的数："))
# print(sum_number(number_in))

# 18、编写一个函数，求多个数中的最大值
# list_ = []
# def max_number(*number):
#     return max(number)
# number_n = input("请输入您要判断的数字：用空格隔开\n").split()
# for  i in number_n:
#     list_.append(int(i))
# print(max_number(*list_))
# 19、编写一个函数，提取指定字符串中所有的字母，然后拼接在一起产生一个新的字符串
# montage_str = []
# def montage(*str):
#     for i in str:
#         global montage_str
#         montage_str.append(i)
#     # print(montage_str)
#     for j in montage_str:
#         print(j,end="")
# montage_str_name = input("请输入您要连接的字符串中间用逗号隔开！！\n").split(",")
# montage(*montage_str_name)

# 20、编写一个函数，使用冒泡排序将一个列表由大到小排序
# def bubble_sort(lst):
#     for i in range(len(lst)-1):
#         for j in range(len(lst)-1-i):
#             if lst[j] < lst[j+1]:
#                 lst[j],lst[j+1] = lst[j+1],lst[j]
#     return lst
# list_ = []
# bubble_number = input("请您输入要判断的数字：中间用空格隔开！\n").split()
# for  i in bubble_number:
#     list_.append(int(i))
# print(bubble_sort(list_))
# 21、写一个函数，求多个数的平均值
# sum = 0
# k = 0
# def avg_number(*number):
#     for i in number:
#         global sum
#         global k
#         sum +=i
#         k +=1
#     return sum/k
# list_ = []
# number_avg_n = input("请您输入您要判断的数字：中间用空格隔开！！\n").split()
# for i in number_avg_n:
#     list_.append(int(i))
# print(f"您输入的值平均数为：{avg_number(*list_)}")
# 22、写一个自己的len函数，统计指定序列中元素的个数
# def len_(str_):
#     k =0
#     for  i in str_:
#         k+=1
#     return k
# str_ing = input("请输入您要判断的字符串：")
# print(len_(str_ing))
# 23、找出传入的列表或元组的奇数位对应的元素，并返回一个新的列表
# list_number =[]
# def list_(*a):
#     list_number = a
#     return list_number
# list_number_input = input("请您输入您要判断的元素：中间用空格隔开！！").split()
# list_number_input_up = []
# for i in list_number_input:
#     list_number_input_up.append(int(i))
# print(list(list_number_input_up)[1::2])
# 24、水仙花数：个位、十位、百位的立方加在一起等于数的本身，
# import random
# def Narcissistic_number(number):
#     hundred_number = number//100
#     ten_number = (number//10)%10
#     unit_number = number%10
#     sum = 0
#     sum = hundred_number **3 + ten_number**3 + unit_number**3
#     if sum == number:
#         print(f"{number}是水仙花数")
#     # else:
#     #     print(f"{number}不是水仙花数")
#
# na_number = random.randint(100,1000)
# for i in range(100,999):
#     Narcissistic_number(i)

# 25、定义函数，有一个形参，传入的是列表
# ，数组大小不超过 100个，
# # 数组中的每个元素值不允许超过 100，但是可以等于100，
# # 如果列表大小超过了100个截取到第100个为止，要求返回的列表格式：
#
# # 删除所有重复元素，使得每个元素只出现一次
# # 按照数字的大小，由高到低排序返回
# import  random
# def list_number(*list_1):
#     new_list = list(set(list_1))
#     if len(new_list) > 100:
#         new_list1=new_list[0:99]
#         print(new_list1)
#         new_list1.sort(reverse = True)
#         print(new_list1)
#     else:
#         print(new_list)
#         new_list.sort(reverse=True)
#         print(new_list)
# list_number_li = []
# for  i in range(200):
#     number_random = random.randint(0,200)
#     list_number_li.append(number_random)
# list_number(*list_number_li)
# 26、定义函数 getLength，打印用户传入的容器类型和数据长度
# def getLength(str_):
#     print(type(str_))
#     print(len(str_))
#
# str_k_list = input("请您输入您要判断的字符串").split()
# getLength(*str_k_list)
# 27、定义函数 generateNum( )
# # 返回从0~9的十个数字中随机取出4个不重复的数字组成一个字符串
# import  random
# def generateNum():
#     list_ = []
#     for i in range(0,10):
#         random_number = random.randint(0, 9)
#         list_.append(random_number)
#         new_list= list(set(list_))
#         new_list.sort(reverse = True)
#     for i in new_list[0:4]:
#         str_num = str(i)
#         print(str_num,end="")
# generateNum()
# 28、定义函数 moreThan(num)，判断输入的数字是否大于1500
# def moreThan(num):
#     if num >1500:
#         print("大于1500")
#     if num < 1500:
#         print("小于1500")
#     if num == 1500:
#         print("等于1500")
# number_than = int(input("请输入您要判断的数："))
# moreThan(number_than)
# 29、定义函数，有两个形参，第一个形参到第二个形参的范围，所有平方数之和
#
# 示例：func_a(5,10)
# 5x5+6x6+7x7+8x8+9x9+10x10...
# sum_number = 0
# def func_a(first_num,second_num):
#     global sum_number
#     for  i in range(first_num,second_num+1):
#         sum_number += i*i
#     return sum_number
# first_number1 = int(input("请输入第一个值："))
# first_number2 = int(input("请输入第二个值："))
# print(func_a(first_number1, first_number2))
# 30、写函数，检查传入字典的每一个value长度，如果大于2，
# # 那么仅保留前两个长度的内容， 并将新内容返回给调用者
# def dict_value_len(**dict_it):
#     dict_input = {}
#     for key,value in dict_it.items():
#         if len(value) >2:
#             dict_input[key] = value[0:2]
#         else:
#             dict_input[key] = value
#     return dict_input
# name_input = input("请输入您要判断的姓名：")
# age_input = input("请输入您要判断的年龄：")
# address_input = input("请输入您要判断的地址：")
# print(dict_value_len(姓名=name_input,年龄=age_input,地址=address_input))
# 31、写函数，判断用户传入的对象（字符串、列表、元组）的元素是否为空
# def input_is_not_null(*str):
#     if len(*str) ==0:
#         print("您输入的字符串为空")
#     else:
#         print("您输入的字符串不为空")
# str_input = input("请输入您要判断的字符串：")
# input_is_not_null(str_input)
# 32、编写自定义函数，完成一个简单的减法运算函数
# subtraction_nu = 0
# def subtraction_number(first_number,second_number):
#     global subtraction_nu
#     subtraction_nu = first_number -second_number
#     return subtraction_nu
# first_nu = int(input("请输入第一个数："))
# second_nu = int(input("请输入第二个数："))
# print(subtraction_number(first_nu, second_nu))
# 33、编写自定义函数，可以输出自己的名字即可。
# def name_person(name):
#     print(name)
# name = input("请输入您的姓名：")
# name_person(name)
# 34、编写自定义函数：剪刀石头布
# 游戏开始，初始状态下用户和电脑都有 100 分，赢一局+10 分，输一局-10 分。
#
# 当用户为 0 分时，游戏结束，提示游戏结束，比赛输了
#
# 当用户为 200 分时，游戏结束，提示游戏结束，赢得比赛、每轮比赛都输出当前的分数
#
# 1 代表剪刀 2 代表石头 3 代表布
# import random
# def stone_scissors_cloth(game_nu):
#     person_score = 100
#     computer_score = 100
#     cpmputer_nu = random.randint(1,3)
#     print(cpmputer_nu)
#     if (game_nu == 1 and cpmputer_nu ==1) or  (game_nu == 2 and cpmputer_nu ==2) or (game_nu == 3 and cpmputer_nu ==3) :
#         print("平局!")
#     if game_nu == 1 and cpmputer_nu == 2:
#         print("电脑获胜!")
#     if game_nu == 1 and cpmputer_nu ==3:
#         print("玩家获胜")
#     if game_nu == 2 and cpmputer_nu ==1:
#         print("玩家获胜")
#     if game_nu == 2 and cpmputer_nu ==3:
#         print("电脑获胜")
#     if game_nu == 3 and cpmputer_nu ==1:
#         print("电脑获胜")
#     if game_nu == 3 and cpmputer_nu ==2:
#         print("玩家获胜")
# game_s_c = int(input("请您进行猜拳！1 代表剪刀 2 代表石头 3 代表布"))
# stone_scissors_cloth(game_s_c)
# 35、编写一个函数，接受一个字符串作为参数，并返回该字符串的逆序字符串
# def reverse_string(str_input):
#     reverse_str = str_input[::-1]
#     return reverse_str
# reverse_str = input("请输入一个字符串")
# print(reverse_string(reverse_str))
# 36、编写一个函数，接受一个数字列表作为参数，并返回其中所有偶数的列表
# def even_number(*e_number):
#     e_number1 = []
#     for i in e_number:
#         if int(i) % 2 ==0:
#             e_number1.append(i)
#     return e_number1
# list_ = []
# even_number_input = input("请您输入您要判断的数字：").split()
# for  i in even_number_input:
#     list_.append(int(i))
# print(even_number(*list_))
# 37、编写一个函数，接受一个字符串列表作为参数，并返回其中最长的字符串。
# def len_max_string(*string_):
#     max_string = ""
#     for i in string_:
#         # print(len(i))
#         if len(max_string) < len(i):
#             max_string = i
#     print(max_string)
# len_list = []
# len_max_string_input = input("请输入您要判断的字符串：中间用空格隔开").split()
# for i in len_max_string_input:
#     len_list.append(i)
# len_max_string(*len_list)
# 38、编写一个函数，接受一个数字列表作为参数，并返回其中所有数字的平方的总和
# def square_sum(*number_):
#     sum = 0
#     for  i in number_:
#         # print(i)
#         sum += i**2
#         # print(f"sum值{sum}")
#     return sum
# list_ = []
# square_number_input = input("请您输入您要判断的数字：中间用空格隔开！！").split()
# for  i in square_number_input:
#     list_.append(int(i))
# print(f"总和为：{square_sum(*list_)}")
# 39、编写一个函数，接受一个整数作为参数，并返回其阶乘
# def factorial_number(number_):
#     sum =1
#     while number_ >=2:
#         sum *=number_
#         number_ -=1
#     return sum
# number_ = int(input("请输入你要计算的阶乘："))
# print(f"{number_}的阶乘为：{factorial_number(number_)}")
# 40、编写一个函数，接受一个字符串作为参数，并返回其中所有单词的首字母的大写形式
# def string_capitalize(str_):
#     new_str = str_.capitalize()
#     print(new_str)
# str_input = input("请您输入您想判断的字符串")
# string_capitalize(str_input)
# 41、编写一个函数，接受一个字符串列表作为参数，并返回一个字符串，其中包含所有字符串首字母的大写形式
# def string_capitalize(str_):
#     new_str = str_.capitalize()
#     print(new_str)
# str_input = input("请您输入您想判断的字符串")
# string_capitalize(str_input)
# 42、编写一个函数，接受两个列表作为参数，并返回两个列表的交集
#
# 举例：
# list1 = [100,200,300,454]
# list2 = [454,789,125,46]
# new_list = []
# # 返回：[454]
# def intersection_list(list1,list2):
#     for i in list1:
#         # print(i)
#         for j in list2:
#             # print(j)
#             if i == j:
#                 global new_list
#                 new_list.append(i)
#     return new_list
# print(f"相同值为：{intersection_list(list1, list2)}")
# 43、 定义一个学生注册函数enroll()，打印学生姓名，性别，年龄，城市， 使用默认参数降低调用函数的复杂度
# def enroll(**student_information):
#     print(student_information)
# student_name = input("请输入学生姓名：")
# student_sex = input("请输入学生性别：")
# student_age = input("请输入学生年龄：")
# student_address = input("请输入学生城市：")
# enroll(姓名=student_name,性别=student_sex,年龄=student_age,城市=student_address)